/*
 * schedule.S
 *
 *  Created on: May 1, 2015
 *      Author: mxw
 */

/*
		           offset
		+------+
		|cpsr  |    64
		+------+
		|pc_r15|    60
		+------+
		|lr_r14|    56
		+------+
		|sp_r13|    52
		+------+
		| r12  |    48
		+------+
		| r11  |    44
		+------+
		| r10  |    40
		+------+
		| r9   |    36
		+------+
		| r8   |    32
		+------+
		| r7   |    28
		+------+
		| r6   |    24
		+------+
		| r5   |    20
		+------+
		| r4   |    16
		+------+
		| r3   |    12
		+------+
		| r2   |    8
		+------+
		| r1   |    4
		+------+
		| r0   |    0
		+------+

*/

.global restore_run
restore_run:
	mov r3, r0 @back up r0 to r3
	add r0, r3, #64 @now r0 -> cpsr position
	ldr r0, [r0]
	msr cpsr, r0

	ldmia r3, {r0-r12, r13, r14, r15}
/*
	mov r3, r0 @back up r0 to r3

	@recover pc to tmp_value
	add r0, r3, #60 @now r0 -> pc_r15 position
	ldr r0, [r0]
	ldr r1, =sche_tmp_pc
	str r0, [r1]

	@recover cpsr
	add r0, r3, #64 @now r0 -> cpsr position
	ldr r0, [r0]
	msr cpsr, r0

	@save r0 to sche_tmp_r0
	mov r0, r3

	@recover r1
	add r0, r0, #4 @now r0 -> r1 position
	ldr r1, [r0]

	add r0, r0, #4 @now r0 -> r2 position
	ldr r2, [r0]

	add r0, r0, #4 @now r0 -> r3 position
	ldr r3, [r0]

	add r0, r0, #4 @now r0 -> r4 position
	ldr r4, [r0]

	add r0, r0, #4 @now r0 -> r5 position
	ldr r5, [r0]

	add r0, r0, #4 @now r0 -> r6 position
	ldr r6, [r0]

	add r0, r0, #4 @now r0 -> r7 position
	ldr r7, [r0]

	add r0, r0, #4 @now r0 -> r8 position
	ldr r8, [r0]

	add r0, r0, #4 @now r0 -> r9 position
	ldr r9, [r0]

	add r0, r0, #4 @now r0 -> r10 position
	ldr r10, [r0]

	add r0, r0, #4 @now r0 -> r11 position
	ldr r11, [r0]

	add r0, r0, #4 @now r0 -> r12 position
	ldr r12, [r0]

	add r0, r0, #4 @now r0 -> sp_r13 position
	ldr sp, [r0]

	add r0, r0, #4 @now r0 -> lr_r14 position
	ldr lr, [r0]

	add r0, r0, #4 @now r0 -> pc_r15 position
	add r0, r0, #4 @now r0 -> cpsr position
	sub r0, r0, #64 @now r0 -> r0 position
	ldr r0, [r0]

	ldr pc, =sche_tmp_pc
	*/


.global set_task_sp
set_task_sp:
	mov sp, r0
	mov pc, lr


